package com.central.comment.controller

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.central.comment.pojo.comment.CommentDto
import com.central.comment.service.CommentService
import com.central.common.annotation.LoginUser
import com.central.common.entity.Comment
import com.central.common.enum.CommentTypeEnum
import com.central.common.model.*
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import springfox.documentation.annotations.ApiIgnore

/**
 * @author  fly
 * @date  2021/5/28 15:17
 * @version 1.0
 */
@Api(tags = ["(小程序) 评论api"])
@RestController
@RequestMapping("comment")
open class CommentController {

    @Autowired
    private lateinit var commentService: CommentService


    @ApiOperation("添加评论")
    @PostMapping("/insertComment")
    fun insertComment(commentDto: CommentDto, @ApiIgnore @LoginUser sysUser: SysUser): CommonResult<Boolean> = commentService.insertComment(commentDto, sysUser)


    @ApiOperation("移除评论")
    @PostMapping("/removeComment")
    fun removeComment(ids: String): CommonResult<Boolean> = commentService.removeComment(ids)


    @ApiOperation("(rpc) 获取某个帖子的全部评论信息")
    @GetMapping("/getCommentVoListByRelevanceId")
    fun getCommentVoListByRelevanceId(relevanceId: Long, sysUser: SysUser, pageVo: PageVo, commentTypeEnum: CommentTypeEnum): Page<CommentVo>? = commentService.getCommentVoListByRelevanceId(relevanceId, sysUser, pageVo, commentTypeEnum)


    @ApiOperation("(rpc) 获取某个类型的全部评论数量")
    @GetMapping("/getCommentNumByRelevanceId")
    fun getCommentNumByRelevanceId(relevanceId: Long, commentTypeEnum: CommentTypeEnum): Long = commentService.getCommentNumByRelevanceId(relevanceId, commentTypeEnum)


    @ApiOperation("(rpc) 获取某个人在某个类型的全部评论信息")
    @GetMapping("/getCommentVoListByUserId")
    fun getCommentVoListByUserId(userId: Long, commentTypeEnum: CommentTypeEnum): List<Comment>? =
        commentService.getCommentVoListByUserId(userId, commentTypeEnum)


    @ApiOperation("(rpc) 获取某个类型的全部评论人")
    @GetMapping("/getCommentAllUserIds")
    fun getCommentAllUserIds(commentTypeEnum: CommentTypeEnum, pageVo: PageVo): Page<Long>? =
        commentService.getCommentAllUserIds(commentTypeEnum, pageVo)


    @ApiOperation("(rpc) 添加评论")
    @PostMapping("/insertRpcComment")
    fun insertComment(commentRpcDto: CommentRpcDto): Comment? =
        commentService.insertComment(commentRpcDto)


    @ApiOperation("(rpc) 根据内容评论人评论类型获取评论数据")
    @GetMapping("/getCommentByContentAndUserIdAndTypeAndRelevanceId")
    fun getCommentByContentAndUserIdAndTypeAndRelevanceId(content: String, userId: Long, commentTypeEnum: CommentTypeEnum, relevanceId: Long): Comment? =
        commentService.getCommentByContentAndUserIdAndTypeAndRelevanceId(content, userId, commentTypeEnum, relevanceId)
}
